<?php
error_reporting(E_ALL);
require_once(__DIR__.'/../include/Autoload.php');

Common::init(dirname($_SERVER['SCRIPT_NAME']));

$router = new AltoRouter();
$router->setBasePath(HTTP_ENTRY);

$router->map('GET', '/', function(){
    global $active;
    $active = 'list';
    Common::view('index.phtml');
});
$router->map('GET', '/test', function(){
    global $active;
    $active = 'list';
    Common::view('test.phtml');
});
$router->map('GET|POST', '/upload', function(){
    global $active;
    $active = 'list';
    Common::view('upload.phtml');
});
$router->map('GET', '/subset', function(){
    header('Content-Type:text/javascript');

    Common::view('subset.phtml', false);
});
$router->map('GET', '/font.js', function(){
    header('Content-Type:text/javascript');
    Common::view('js.phtml', false);
});

$router->map('GET', '/example', function(){
    global $active;
    $active = 'list';
    Common::view('sample.phtml');
});

$match = $router->match();
// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] );
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}



